/*
 * @Author: linxun 
 * @Date: 2021-05-26 16:35:25 
 * @Last Modified by: linxun
 * @Last Modified time: 2021-06-21 11:04:23
 * @Description: 数据集发布Modal
 */

import React, { useState } from 'react';
import { Modal, Switch, Alert, Form } from 'antd';

interface Props {
  visible: boolean;
  cancel: () => void;
  onSubmit: (dataSetIsPublic: boolean) => void;
  loading: boolean;
}

const commonLayout = {
  labelCol: { span: 6 },
  wrapperCol: { span: 18 },
};

const ReleaseModal: React.FC<Props> = props => {
  const { visible, cancel, onSubmit, loading } = props;
  const [dataSetIsPublic, setDataSetIsPublic] = useState(true);

  return (
    <Modal
      title='数据集发布'
      visible={visible}
      onCancel={cancel}
      onOk={() => onSubmit(dataSetIsPublic)}
      maskClosable={false}
      okText='确认发布'
      confirmLoading={loading}
      width={600}
    >
      <Alert
        showIcon
        message='发布后不可修改，请问是否发布此数据集？'
        type='warning'
        style={{ marginBottom: 24 }}
      />
      <Form.Item
        label='公开数据'
        {...commonLayout}
        extra='公开数据开启后所有用户可见，关闭只对本组用户可见'
        style={{ marginBottom: 0 }}
      >
        <Switch
          checkedChildren='是'
          unCheckedChildren='否'
          checked={dataSetIsPublic}
          onChange={checked => setDataSetIsPublic(checked)}
        />
      </Form.Item>
    </Modal>
  )
}

export default ReleaseModal;